<template>
	<view class="content font_family">
		<view class="js_box">
			<view class="j_box f_j">
				<view class="tag f_zj">
					寄
				</view>
				<view class="msg">
					<view class="tip" v-if="!query_data.j_info.address">
						<view class="title">
							从哪寄快递
						</view>
						<!-- <view class="zn" >
							智能填写
						</view> -->
					</view>
					<view class="message" v-else>
						<view class="name f">
							<view class="">
								{{query_data.j_info.name}}
							</view>
							<view class="tel">
								{{query_data.j_info.tel}}
							</view>
						</view>
						<view class="address">
							{{query_data.j_info.address}}
						</view>
					</view>
				</view>
				<view class="dztx" @click.stop="go('/pages/my_msg/sh_address?msg=jh')">
					地址填写
				</view>
			</view>
			<view class="s_box f_j">
				<view class="tag f_zj">
					收
				</view>
				<view class="msg">
					<view class="tip" v-if="!query_data.s_info.name">
						<view class="title">
							要寄到哪
						</view>
						<!-- <view class="zn">
							智能填写
						</view> -->
					</view>
					<view class="message" v-else>
						<view class="name f">
							<view class="">
								{{query_data.s_info.name}}
							</view>
							<view class="tel">
								{{query_data.s_info.tel}}
							</view>
						</view>
						<view class="address">
							{{query_data.s_info.address}}
						</view>
					</view>
				</view>
				<!-- <view class="dztx" @click="go(`/pages/order/tx_dz?type=s`)">
					地址填写
					@click="go(`/pages/order/tx_dz?type=j`)"
				</view> -->
			</view>
		</view>
		<view class="wl_id f_j f_z_b">
			<view class="left">
				物流单号
			</view>
			<view class="right">
				<u--input placeholder="请输入快递单号" border="none" v-model="query_data.w_no" inputAlign='right'></u--input>
			</view>
		</view>
		<view class="btn" @click="sub">
			确定寄回
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import { mapState, mapMutations } from 'vuex'
	import { exchange } from '@/api/user.js'
	export default {
		computed: {
			...mapState(['j_msg', 's_msg'])
		},
		data() {
			return {
				query_data: {
					j_info: {
						name: '',
						tel: '',
						address: '',
						xx_address: '',
					},
					s_info: {
						name: '',
						tel: '',
						address: '',
						xx_address: '',
					},
					order_detail_id: '',
					w_no: '',
				}
			}
		},
		onLoad(e) {
			this.query_data.order_detail_id = e.id
			this.query_data.s_info = JSON.parse(e.msg)
		},
		watch: {
			j_msg(newval, old) {
				this.query_data.j_info.name = newval.name
				this.query_data.j_info.tel = newval.tel
				this.query_data.j_info.address = newval.address
				this.query_data.j_info.xx_address = newval.xx_address
			},
			// s_msg(newval, old) {
			// 	this.query_data.s_info.name = newval.name
			// 	this.query_data.s_info.tel = newval.tel
			// 	this.query_data.s_info.address = newval.address
			// 	this.query_data.s_info.xx_address = newval.xx_address
			// }
		},
		methods: {
			sub() {
				if (!this.query_data.j_info.name) {
					uni.showToast({
						icon: 'none',
						title: '请填写寄货信息'
					})
					return
				}
				if (!this.query_data.s_info.name) {
					uni.showToast({
						icon: 'none',
						title: '请填写收货信息'
					})
					return
				}
				if (!this.query_data.w_no) {
					uni.showToast({
						icon: 'none',
						title: '请填写物流单号'
					})
					return
				}
				exchange(this.query_data).then(res => {
					if (res.code == 1) {
						this.$refs.uToast.show({
							type: 'default',
							message: res.msg,
							duration: 1500,
							complete: () => {
								this.back()
							}
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		padding: 30rpx;

		.js_box {
			padding: 30rpx;
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;

			.j_box {
				padding-bottom: 40rpx;
				border-bottom: 1rpx solid #E1E1E1;

				.tag {
					width: 78rpx;
					height: 78rpx;
					background: #FF6262;
					border-radius: 50%;
					font-weight: 400;
					font-size: 32rpx;
					color: #FFFFFF;
				}
			}

			.s_box {
				padding-top: 40rpx;

				.tag {
					width: 78rpx;
					height: 78rpx;
					background: #45BEFF;
					border-radius: 50%;
					font-weight: 400;
					font-size: 32rpx;
					color: #FFFFFF;
				}
			}

			.msg {
				flex: 1;
				margin-left: 20rpx;

				.tip {
					.title {
						font-weight: 400;
						font-size: 32rpx;
						color: #3D3D3D;
					}

					.zn {
						margin-top: 10rpx;
						font-weight: 400;
						font-size: 28rpx;
						color: #666666;
					}
				}

				.message {
					.name {
						font-weight: 400;
						font-size: 32rpx;
						color: #3D3D3D;

						.tel {
							margin-left: 15rpx;
						}
					}

					.address {
						margin-top: 10rpx;
						font-weight: 400;
						font-size: 28rpx;
						color: #666666;
					}
				}
			}

			.dztx {
				margin-left: 20rpx;
				font-weight: 400;
				font-size: 24rpx;
				color: #999999;
			}
		}

		.wl_id {
			margin-top: 30rpx;
			padding: 30rpx;
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
		}

		.btn {
			margin-top: 60rpx;
			text-align: center;
			padding: 24rpx;
			background: #EE4133;
			border-radius: 22rpx 22rpx 22rpx 22rpx;
			font-weight: 400;
			font-size: 28rpx;
			color: #FFFFFF;
		}
	}
</style>